package com.scoy.honeymei.activity.mall;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.R;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.bean.TravelBuyBean;
import com.scoy.honeymei.bean.TravelOrderBean;
import com.scoy.honeymei.bean.TravelPreBean;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.MeConstant;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.GlideImgUtil;
import com.scoy.honeymei.utils.MyUtil;
import com.scoy.honeymei.utils.SPHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: TravelMeDetailActivity$
 * @Description: 我的订单旅行详情
 * @Author: GaoZhan
 * @CreateDate: 2019/9/9/0009$ 下午 14:53$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/9/0009$ 下午 14:53$
 * @UpdateRemark: 更新内容
 */
public class TravelMeDetailActivity extends BaseActivity {

    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.title_tv)
    TextView titleTv;
    @BindView(R.id.sign_tv)
    TextView signTv;
    @BindView(R.id.title_llt)
    LinearLayout titleLlt;
    @BindView(R.id.itl_img_iv)
    ImageView itlImgIv;
    @BindView(R.id.itl_name_tv)
    TextView itlNameTv;
    @BindView(R.id.itl_tv0)
    TextView itlTv0;
    @BindView(R.id.itl_traveltype_tv)
    TextView itlTraveltypeTv;
    @BindView(R.id.itl_tv1)
    TextView itlTv1;
    @BindView(R.id.itl_date_tv)
    TextView itlDateTv;
    @BindView(R.id.itl_sign_iv)
    ImageView itlSignIv;
    @BindView(R.id.dtm_tv0)
    TextView dtmTv0;
    @BindView(R.id.dtm_name_tv)
    TextView dtmNameTv;
    @BindView(R.id.dtm_tv1)
    TextView dtmTv1;
    @BindView(R.id.dtm_phone_tv)
    TextView dtmPhoneTv;
    @BindView(R.id.dtm_tv3)
    TextView dtmTv3;
    @BindView(R.id.dtm_mannum_tv)
    TextView dtmMannumTv;
    @BindView(R.id.dtm_tv4)
    TextView dtmTv4;
    @BindView(R.id.dtm_childnum_tv)
    TextView dtmChildnumTv;
    @BindView(R.id.dtm_tv5)
    TextView dtmTv5;
    @BindView(R.id.dtm_sigleprice_tv)
    TextView dtmSiglepriceTv;
    @BindView(R.id.dtm_tv6)
    TextView dtmTv6;
    @BindView(R.id.dtm_chargeprice_tv)
    TextView dtmChargepriceTv;
    @BindView(R.id.dtm_tv7)
    TextView dtmTv7;
    @BindView(R.id.dtm_allprice_tv)
    TextView dtmAllpriceTv;
    @BindView(R.id.dtm_cl0)
    ConstraintLayout dtmCl0;
    @BindView(R.id.dtm_tv2)
    TextView dtmTv2;
    @BindView(R.id.dtm_content_tv)
    TextView dtmContentTv;
    @BindView(R.id.dtm_cl1)
    ConstraintLayout dtmCl1;
    @BindView(R.id.dtm_tv8)
    TextView dtmTv8;
    @BindView(R.id.dtm_tv9)
    TextView dtmTv9;
    @BindView(R.id.dtm_ordernum_tv)
    TextView dtmOrdernumTv;
    @BindView(R.id.dtm_tv10)
    TextView dtmTv10;
    @BindView(R.id.dtm_creattime_tv)
    TextView dtmCreattimeTv;
    @BindView(R.id.dtm_tv11)
    TextView dtmTv11;
    @BindView(R.id.dtm_paytime_tv)
    TextView dtmPaytimeTv;
    private TravelMeDetailActivity mContext;
    private int type;
    private int travelId;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_travelme_detail);
        ButterKnife.bind(this);
        mContext = TravelMeDetailActivity.this;
        type = getIntent().getIntExtra("type", 0);
        travelId = getIntent().getIntExtra("travelId", 0);

        initNormal();

        if (type == 0) {
            dtmCl0.setVisibility(View.GONE);
            dtmCl1.setVisibility(View.VISIBLE);

            dtmPaytimeTv.setVisibility(View.GONE);
            dtmTv11.setVisibility(View.GONE);

            httpTravelBook();

        } else {
            itlSignIv.setVisibility(View.GONE);

            httpTravelBuy();
        }


    }

    @Override
    public void initNormal() {
        titleTv.setText(R.string.orderdetail);

        MyUtil.setStatusBar(mContext, getWindow(), true, R.color.colorWhite);
        titleLlt.setPadding(0, MyUtil.getStatusBarHeight(mContext), 0, 0);

    }

    @OnClick({R.id.back_iv, R.id.title_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.title_tv:
                break;
        }
    }

    private void httpTravelBook() {
        HttpParams params = new HttpParams();
        params.put("about_id", travelId);
        params.put("uid", SPHelper.getString(MeConstant.UID, ""));
        HpGo.newInstance().HttpGo(this, MyUrl.TRAVELBOOK_ORDER_DETAIL, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                TravelPreBean travelPreBean = new Gson().fromJson(o, TravelPreBean.class);
                GlideImgUtil.glidePic(mContext, travelPreBean.getImage(), itlImgIv);
                itlNameTv.setText(travelPreBean.getJingdian_name());
                itlTraveltypeTv.setText(travelPreBean.getType_name());
                itlDateTv.setText(travelPreBean.getAbouttime());

                int stateswitch = travelPreBean.getStateswitch();

                if (stateswitch == 1) {
                    itlSignIv.setImageResource(R.drawable.ic_review_ed);
                } else {
                    itlSignIv.setImageResource(R.drawable.ic_review_pre);
                }


                dtmNameTv.setText(travelPreBean.getName());
                dtmPhoneTv.setText(travelPreBean.getTel());
                dtmContentTv.setText(travelPreBean.getDetail());

                dtmOrdernumTv.setText(travelPreBean.getOrder_no());
                dtmCreattimeTv.setText(travelPreBean.getCreatetime());

            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, code + "," + msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }

    private void httpTravelBuy() {
        HttpParams params = new HttpParams();
        params.put("order_id", travelId);
        params.put("uid", SPHelper.getString(MeConstant.UID, ""));
        HpGo.newInstance().HttpGo(this, MyUrl.TRAVELBUY_ORDER_DETAIL, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                TravelBuyBean travelBuyBean = new Gson().fromJson(o, TravelBuyBean.class);

                GlideImgUtil.glidePic(mContext, travelBuyBean.getImage(), itlImgIv);
                itlNameTv.setText(travelBuyBean.getJingdian_name());
                itlTraveltypeTv.setText(travelBuyBean.getType_name());
                itlDateTv.setText(travelBuyBean.getTouristtime());
                dtmNameTv.setText(travelBuyBean.getName());
                dtmPhoneTv.setText(travelBuyBean.getTel());
                dtmMannumTv.setText(travelBuyBean.getNum() + "");
                dtmChildnumTv.setText(travelBuyBean.getChildnum() + "");
                dtmSiglepriceTv.setText("￥" + travelBuyBean.getOld_money());
                dtmChargepriceTv.setText("-￥" + travelBuyBean.getCoupon_money());
                dtmAllpriceTv.setText("￥" + travelBuyBean.getMoney());
                dtmOrdernumTv.setText(travelBuyBean.getOrder_no());
                dtmCreattimeTv.setText(travelBuyBean.getCreatetime());
                dtmPaytimeTv.setText(travelBuyBean.getPaytime());
            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, code + "," + msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }
}
